//
//  DetailShareView.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/9/20.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol DetailShareViewDelegate {
    func wechatCircle()
    func wechatFriend()
    func qqFriend()
    func qqZone()
    func weibo()
    func foneSize()
    func report()
    func collection()

}
class DetailShareView: UIView {
    
    @IBOutlet var customView: UIView!
    var delegate: DetailShareViewDelegate?
    var maxHeight: CGFloat = 0
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.commonInit()
    }
    
    
    func commonInit () {
        NSBundle.mainBundle().loadNibNamed("DetailShareView", owner: self, options: nil)
        //self.customView.frame.size.width = self.frame.size.width
        self.customView.width(self.width)
        self.customView.height(164)
        self.customView.bottom(self.bottom())
        self.customView.frame.origin.x = 0
        self.backgroundColor = UIColor.clearColor()
        self.alpha = 0
        
        
        let maskView:UIView = UIView.init(frame: self.bounds)
        maskView.backgroundColor = UIColor.blackColor()
        maskView.alpha = 0.5
        self.addSubview(maskView)
        
        self.addSubview(self.customView)
        let tap = UITapGestureRecognizer.init(target: self, action:#selector(DetailShareView.tapClick(_:)))
        maskView.addGestureRecognizer(tap)
        self.changeFrame()
        
    }
    
    func tapClick (sender:UITapGestureRecognizer) {
        self.closeBtnClick()
    }
    
    func changeFrame(){
        
        if maxHeight == kScreen_height {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.customView.frame.origin.y = kScreen_height
                self.alpha = 0
            })
        } else {
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.alpha = 1
                self.customView.top(0)
            })
        }
    }
    
        
    func closeBtnClick() {
        maxHeight = kScreen_height
        self.changeFrame()
       
    }
    @IBAction func wechatCircle(sender: UIButton){
        delegate?.wechatCircle()
        self.closeBtnClick()
        
    }
    @IBAction func wechatFriend(sender: UIButton){
        delegate?.wechatFriend()
        self.closeBtnClick()
        
    }
    @IBAction func qqFriend(sender: UIButton){
        delegate?.qqFriend()
        self.closeBtnClick()
        
    }
    @IBAction func qqZone(sender: UIButton){
        delegate?.qqZone()
        self.closeBtnClick()
        
    }
    @IBAction func weibo(sender: UIButton){
        delegate?.weibo()
        self.closeBtnClick()
        
    }
    @IBAction func foneSize(sender: UIButton){
        delegate?.foneSize()
        self.closeBtnClick()
    }
    @IBAction func report(sedner: UIButton){
        delegate?.report()
        self.closeBtnClick()
    }
    @IBAction func collection(sedner: UIButton){
        delegate?.collection()
        self.closeBtnClick()
    }
}
